<?php
class EWebby_Data_MySql_MySqlConnection implements EWebby_Data_IDbConnection {
	private $_conn;
	public $properties;

	
	public function getConnection() {
		return $this->_conn;
	}
	
	public function open() {
		$this->_conn = @mysql_connect ( $this->properties['host'],
			$this->properties['user'], 
			$this->properties['password'] );
		if ($this->_conn == null) {
			throw new EWebby_Data_DbConnectionException("failed to connect into database server [{$this->properties['host']}]");
		}
		
		if( @mysql_select_db ( $this->properties['database'] ) == null ) {
			throw new EWebby_Data_DbException("failed to open connection with [{$this->properties['database']}] database");
		}
	}

	public function close() {
		return isset($this->_conn)?
			@mysql_close($this->_conn) : @mysql_close();
	}
	
	public function createCommand() {
		return new EWebby_Data_MySql_MySqlCommand($this);
	}
	
	public function beginTransaction() {
		@mysql_query ( 'SET AUTOCOMMIT=0', $this->_conn );
		@mysql_query ( 'START TRANSACTION', $this->_conn );
	}
	public function commitTransaction() {
		@mysql_query ( 'COMMIT', $this->_conn );
		@mysql_query ( 'SET AUTOCOMMIT=1', $this->_conn );
	}
	public function rollBackTransaction() {
		@mysql_query ( 'ROLLBACK', $this->_conn );
		@mysql_query ( 'SET AUTOCOMMIT=1', $this->_conn );
	}
}